package com.begonza;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: bgonzales
 * Date: Sep 21, 2011
 * Time: 11:05:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class DataTable
{
    private List<DataElement> dataElements;
    private String name;


    public DataTable()
    {
        init();    
    }

    private void init()
    {
        if ( null == dataElements )
        {
            dataElements = new ArrayList<DataElement>();
        }
    }

    public DataElement get(String name)
    {
        for (DataElement elem : dataElements )
        {
            if (name == elem.getName())
            {
                return elem;
            }
        }
        return null;
    }
    
    public DataElement add( DataElement e)
    {
        DataElement f = get(e.getName());
        if ( null == f )
        {
            dataElements.add(e);
            return e;
        }
        else
        {
            return null;
        }
    }
    
    public List<DataElement> getDataElements() {
        return dataElements;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
